<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/jh/admin/components/meta.html" />
    <title>员工信息 ${metaTitleSuffix!}</title>
    <#include "/jh/admin/components/stylesheets.html" />
    <style type="text/css">
    .el-select .el-input {
        width: 130px;
    }

    .input-with-select .el-input-group__prepend {
        background-color: #fff;
    }
    </style>
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="3-1" />
            <#include "/jh/admin/components/menu.html" />
            <el-container>
                <#include "/jh/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row>
                            <el-col :span="12">
                                <div class="title theme-color1">员工信息</div>
                            </el-col>
                            <el-col :span="12">
                                <div class="operations">
                                    <el-button type="success" size="small" @click="add"><i class="el-icon-plus"></i>添加</el-button>
                                </div>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span='12'>
                                <el-input placeholder="姓名/电话,如:刘老师" v-model="keyword" class="input-with-select" clearable>
                                    <el-select v-model="selectedSchool" slot="prepend" placeholder="校区" clearable>
                                        <el-option :label="item.name" :value="item.id" v-for='item in schools'></el-option>
                                    </el-select>
                                    <el-button slot="append" icon="el-icon-search" @click='onSearch'></el-button>
                                </el-input>
                            </el-col>
                            <el-col :span='12'>
                                <el-select v-model="isLeave" placeholder="员工状态" @change='onIsLeaveChanged'>
                                    <el-option label="在职" value="0"></el-option>
                                    <el-option label="离职" value="1"></el-option>
                                </el-select>
                                <template>
                                    <el-select v-model="isMoving" placeholder="异动" clearable @change='onIsMovingChanged'>
                                        <!-- <el-option label="非异动" value="0"></el-option> -->
                                        <el-option label="异动" value="1"></el-option>
                                    </el-select>
                                    <el-select v-model="isTrying" placeholder="试用" clearable @change='onIsTryingChanged'>
                                        <!-- <el-option label="非试用期" value="0"></el-option> -->
                                        <el-option label="试用期" value="1"></el-option>
                                    </el-select>
                                </template>
                                <el-cascader :options="positionTree" v-model="selectedPosition" placeholder='部门/岗位' @change='onPositionChanged' clearable change-on-select>
                                </el-cascader>
                            </el-col>
                        </el-row>
                        <el-row>
                        </el-row>
                        <div class="options">
                            <el-col :sm="24" :md="12" :lg="8" :xl="6">
                                <p>入职日期</p>
                                <el-date-picker v-model="entryDate" type="daterange" range-separator="至" end-placeholder="结束日期" value-format="yyyy-MM-dd" start-placeholder="入职日期" @change='onEntryDateChanged' unlink-panels="true">
                                </el-date-picker>
                            </el-col>
                            <el-col :sm="24" :md="12" :lg="8" :xl="6">
                                <p>试用期开始日期</p>
                                <el-date-picker v-model="tryStartDate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change='onTyrStartDateChanged' unlink-panels="true">
                                </el-date-picker>
                            </el-col>
                            <el-col :sm="24" :md="12" :lg="8" :xl="6">
                                <p>试用期结束日期</p>
                                <el-date-picker v-model="tryEndDate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change='onTryEndDateChanged' unlink-panels="true">
                                </el-date-picker>
                            </el-col>
                            <el-col :sm="24" :md="12" :lg="8" :xl="6">
                                <p>转正日期</p>
                                <el-date-picker v-model="formalDate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change='onFormalDateChanged' unlink-panels="true">
                                </el-date-picker>
                            </el-col>
                            <el-col :sm="24" :md="12" :lg="8" :xl="6">
                                <p>合同开始日期</p>
                                <el-date-picker v-model="contractStartDate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change='onContractStartDateChanged' unlink-panels="true">
                                </el-date-picker>
                            </el-col>
                            <el-col :sm="24" :md="12" :lg="8" :xl="6">
                                <p>合同结束日期</p>
                                <el-date-picker v-model="contractEndDate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change='onContractEndDateChanged' unlink-panels="true">
                                </el-date-picker>
                            </el-col>
                        </div>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%">
                            <el-table-column prop="code" label="员工编号" sortable show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="position" label="部门/岗位" sortable>
                            </el-table-column>
                            <el-table-column prop="name" label="姓名" sortable>
                                <template slot-scope="scope">
                                    <span>{{scope.row.name}}</span>
                                </template>
                            </el-table-column>
                            <template v-if='isLeave == 0'>
                                <el-table-column prop="entryDate" label="入职日期" sortable>
                                </el-table-column>
                            </template>
                            <template v-if='isLeave == 1'>
                                <el-table-column prop="leaveDate" label="离职日期" sortable>
                                </el-table-column>
                                <el-table-column prop="leaveType" label="离职类型" sortable>
                                </el-table-column>
                            </template>
                            <!-- <el-table-column prop="isTeacher" label="是否老师" sortable>
                                <template slot-scope="scope">
                                    <span v-if="scope.row.isTeacher == 1">是</span>
                                    <span v-if="scope.row.isTeacher == 0">否</span>
                                </template>
                            </el-table-column> -->
                            <el-table-column prop="contact1" label="电话1" sortable v-if='isLeave != 1'>
                            </el-table-column>
                            <el-table-column prop="contact2" label="电话2" sortable v-if='isLeave != 1'>
                            </el-table-column>
                            <el-table-column prop="schoolName" label="校区" sortable>
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="100">
                                <template slot-scope="scope">
                                    <!-- <el-button @click="push(scope.row)" type="text" size="small">推送</el-button> -->
                                    <el-button @click="edit(scope.row)" type="text" size="small">编辑</el-button>
                                    <el-button @click="del(scope.row)" type="text" size="small" style="color: red;">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <p><a target="_blank" href="/jh/admin/staff/download"><i class="el-icon-download"></i>下载完整员工信息</a>
                        </p>
                        <#include "/jh/admin/components/page.html" />
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/jh/admin/components/footer.html" />
    </div>
    <#include "/jh/admin/components/scripts.html" />
    <script type="text/javascript" src="/jh/json/position.json"></script>
    <script type="text/javascript" src="/jh/json/positionTree.json"></script>
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                positions: position,
                positionTree: positionTree,
                selectedPosition: [],
                list: [],
                isLeave: '${isLeave!0}',
                isMoving: '${isMoving!}',
                isTrying: '${isTrying!}',
                selectedSchool: '',
                keyword: '${keyword!""}',
                schools: [],
                entryDate: [],
                formalDate: [],
                tryStartDate: [],
                tryEndDate: [],
                contractStartDate: [],
                contractEndDate: [],
                searchPosition: '',
            }
        },
        mounted: function() {
            // var str = '${items!}'
            var str = 'ss'
            if (str != '') {
                this.list = JSON.parse('${items!"[]"}');
            } else {
                alert('加载失败')
            }

            var schoolId = '${schoolId!}'
            if (schoolId != '') {
                this.selectedSchool = Number(schoolId)
            }
            this.schools = JSON.parse('${schools!}')

            var entryDateStart = "${(entryDateStart?date)!''}"
            var entryDateEnd = "${(entryDateEnd?date)!''}"
            if (entryDateStart != '' && entryDateEnd != '') {
                this.entryDate = [entryDateStart, entryDateEnd]
            }


            var tryStartDateStart = "${(tryStartDateStart?date)!''}"
            var tryStartDateEnd = "${(tryStartDateEnd?date)!''}"
            if (tryStartDateStart != '' && tryStartDateEnd != '') {
                this.tryStartDate = [tryStartDateStart, tryStartDateEnd]
            }


            var tryEndDateStart = "${(tryEndDateStart?date)!''}"
            var tryEndDateEnd = "${(tryEndDateEnd?date)!''}"
            if (tryEndDateStart != '' && tryEndDateEnd != '') {
                this.tryEndDate = [tryEndDateStart, tryEndDateEnd]
            }


            var contractStartDateStart = "${(contractStartDateStart?date)!''}"
            var contractStartDateEnd = "${(contractStartDateEnd?date)!''}"
            if (contractStartDateStart != '' && contractStartDateEnd != '') {
                this.contractStartDate = [contractStartDateStart, contractStartDateEnd]
            }


            var contractEndDateStart = "${(contractEndDateStart?date)!''}"
            var contractEndDateEnd = "${(contractEndDateEnd?date)!''}"
            if (contractEndDateStart != '' && contractEndDateEnd != '') {
                this.contractEndDate = [contractEndDateStart, contractEndDateEnd]
            }


            var formalDateStart = "${(formalDateStart?date)!''}"
            var formalDateEnd = "${(formalDateEnd?date)!''}"
            if (formalDateStart != '' && formalDateEnd != '') {
                this.formalDate = [formalDateStart, formalDateEnd]
            }

            var position = '${position!}'
            console.log(position)
            if (position != '') {
                var array = position.split(',')
                array.pop()
                this.selectedPosition = array
            }
        },
        methods: {
            onPositionChanged() {

                var str = ''
                for (var idx = 0; idx < this.selectedPosition.length; idx++) {
                    str = str + this.selectedPosition[idx] + ','
                }
                var keys = [
                    { key: 'position', value: str }
                ]
                goPage(1, keys)

            },
            onEntryDateChanged(val) {
                if (val == null) {
                    var k = [
                        { key: 'entryDateStart', value: "" },
                        { key: 'entryDateEnd', value: "" }
                    ]
                    goPage(1, k)
                    return
                }
                var keys = [
                    { key: 'entryDateStart', value: val[0] + ' 00:00:00' },
                    { key: 'entryDateEnd', value: val[1] + ' 23:59:59' }
                ]
                goPage(1, keys)
            },
            onTyrStartDateChanged(val) {
                if (val == null) {
                    var k = [
                        { key: 'tryStartDateStart', value: "" },
                        { key: 'tryStartDateEnd', value: "" }
                    ]
                    goPage(1, k)
                    return
                }
                var keys = [
                    { key: 'tryStartDateStart', value: val[0] + ' 00:00:00' },
                    { key: 'tryStartDateEnd', value: val[1] + ' 23:59:59' }
                ]
                goPage(1, keys)
            },
            onTryEndDateChanged(val) {
                if (val == null) {
                    var k = [
                        { key: 'tryEndDateStart', value: "" },
                        { key: 'tryEndDateEnd', value: "" }
                    ]
                    goPage(1, k)
                    return
                }
                var keys = [
                    { key: 'tryEndDateStart', value: val[0] + ' 00:00:00' },
                    { key: 'tryEndDateEnd', value: val[1] + ' 23:59:59' }
                ]
                goPage(1, keys)
            },
            onContractStartDateChanged(val) {
                if (val == null) {
                    var k = [
                        { key: 'contractStartDateStart', value: "" },
                        { key: 'contractStartDateEnd', value: "" }
                    ]
                    goPage(1, k)
                    return
                }
                var keys = [
                    { key: 'contractStartDateStart', value: val[0] + ' 00:00:00' },
                    { key: 'contractStartDateEnd', value: val[1] + ' 23:59:59' }
                ]
                goPage(1, keys)
            },
            onContractEndDateChanged(val) {
                if (val == null) {
                    var k = [
                        { key: 'contractEndDateStart', value: "" },
                        { key: 'contractEndDateEnd', value: "" }
                    ]
                    goPage(1, k)
                    return
                }
                var keys = [
                    { key: 'contractEndDateStart', value: val[0] + ' 00:00:00' },
                    { key: 'contractEndDateEnd', value: val[1] + ' 23:59:59' }
                ]
                goPage(1, keys)
            },
            onFormalDateChanged(val) {
                if (val == null) {
                    var k = [
                        { key: 'formalDateStart', value: "" },
                        { key: 'formalDateEnd', value: "" }
                    ]
                    goPage(1, k)
                    return
                }
                var keys = [
                    { key: 'formalDateStart', value: val[0] + ' 00:00:00' },
                    { key: 'formalDateEnd', value: val[1] + ' 23:59:59' }
                ]
                goPage(1, keys)
            },
            onSearch() {
                var _self = this;
                // this.loadingData = true;
                var keys = [
                    { value: this.keyword, key: 'keyword' },
                    { value: this.selectedSchool, key: 'schoolId' }
                ]
                goPage(1, keys)
            },
            onIsMovingChanged() {
                var keys = [
                    { key: 'isMoving', value: this.isMoving }
                ]
                goPage(1, keys)
            },
            onIsTryingChanged() {
                var keys = [
                    { key: 'isTrying', value: this.isTrying }
                ]
                goPage(1, keys)
            },
            onIsLeaveChanged() {
                var keys = [
                    { key: 'isLeave', value: this.isLeave }
                ]
                goPage(1, keys)
            },
            add() {
                window.location.href = "/jh/admin/staff/info";
            },
            edit(item) {
                window.location.href = "/jh/admin/staff/info?staffId=" + item.id;
            },
            push(item) {
                var param = Qs.stringify({
                    staffId: item.id
                });
                axios({
                        url: '/jh/admin/message/send',
                        method: 'post',
                        data: param,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        }
                    })
                    .then(function(response) {

                    })
                    .catch(function(error) {
                        endLoading();
                        msg("删除失败");
                        console.log(error);
                    });
            },
            del(item) {
                var self = this;
                confirm("确认删除？请谨慎操作", "确认", function() {
                    var param = Qs.stringify({
                        staffId: item.id
                    });
                    axios({
                            url: '/jh/admin/staff/delete',
                            method: 'post',
                            data: param,
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            }
                        })
                        .then(function(response) {
                            if (response.data.status == 200) {
                                endLoading();
                                window.location.href = "/jh/admin/staff/list";
                                // msg("登录成功");
                            } else {
                                endLoading();
                                msg(response.data.msg);
                                console.log(response.data);
                            }
                        })
                        .catch(function(error) {
                            endLoading();
                            msg("删除失败");
                            console.log(error);
                        });
                })
            },
            onPageChange(val) {
                // console.log('当前页: {val}' + val);
                goPage(val)
            }
        }
    })
    </script>
    <script>
        vue.list = ${items!};
    </script>
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .operations {
        text-align: right;
    }
    </style>
    <#include "/jh/admin/components/msg.html" />
</body>

</html>